﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MExcel = Microsoft.Office.Interop.Excel;

namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private int so;
        private void Form1_Load(object sender, EventArgs e)
        {
            Random rand = new Random();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 6; i++)
            {
                sb.Append(rand.Next(9).ToString());
            }
            so = int.Parse(sb.ToString());
            CaptchaImage caImage = new CaptchaImage(sb.ToString(), pictureBox1.Width + 30, pictureBox1.Height + 30, "Arial");
            pictureBox1.Image = caImage.Image;
        }

        private void btnAgree_Click(object sender, EventArgs e)
        {
            try
            {
                int testedInt = int.Parse(txtCaptchaText.Text);
                if (testedInt == so)
                {
                    MessageBox.Show("Bạn đã nhập đúng!");
                    this.Form1_Load(this, new EventArgs());
                }
                else
                {
                    MessageBox.Show("Bạn đã nhập sai!");
                    this.Form1_Load(this, new EventArgs());
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Bạn đã nhập sai!");
                this.Form1_Load(this, new EventArgs());
            }
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            this.Form1_Load(this, new EventArgs());
        }

        
    }
}